<template>
  <div>
    <van-nav-bar
      :title="`${$route.query.q}的搜索页`"
      left-arrow
      @click-left="$router.back()"
    />

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell
        v-for="item in list"
        :key="item.art_id"
        :title="item.title"
        @click="
          $router.push({ path: '/myarticle', query: { id: item.art_id } })
        "
      />
    </van-list>
  </div>
</template>

<script>
import { getSearchList } from "./home.js";
export default {
  name: "searchResult",
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
    };
  },
  methods: {
    async onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求

      let ret = await getSearchList({
        page: this.page,
        q: this.$route.query.q,
      });
      this.list = ret.data.data.results;
      this.page++;

      // 加载状态结束
      this.loading = false;

      // 数据全部加载完成
      if ((ret.data.data.results = [])) {
        this.finished = true;
      }
    },
  },
};
</script>

<style>
</style>